<?php

namespace backend\models;

use Yii;
use common\models\UserInfo;
use yii\helpers\ArrayHelper;
use yii\db\ActiveRecord;
use backend\models\Qr;
use backend\models\PayTrade;

class Factory extends \yii\db\ActiveRecord
{
	
 
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'grp_factory';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {    	
        return [
            [['id' ], 'integer'],
            [['name'], 'string', 'max' => 24],
        	[['short_code'],'required'],
        	[['short_code','bank_account'], 'string', 'max' => 50],
            [['addr','delivery_address'], 'string', 'max' => 128],
        	[['email','phone','bank_name','delivery_tel','Responsible_tel'], 'string', 'max' => 64],
        	[['contacts','Responsible_person',], 'string', 'max' => 20],
        		
        ];
    }
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => Yii::t('app','工厂名称'),
            'short_code' => Yii::t('app','简码'),
            'addr' => Yii::t('app','地址'),
            'email' => Yii::t('app','邮箱'),
            'phone' => Yii::t('app','联系方式'),
            'contacts' => Yii::t('app','联系人'),
            'bank_name' => Yii::t('app','开户银行'),
            'bank_account' => Yii::t('app','银行账号'),
            'delivery_address' => Yii::t('app','发货地址'),
            'delivery_tel' => Yii::t('app','发货电话'),
        	'Responsible_person'=>Yii::t('app','平台责任人 '),
        	'Responsible_tel'=>Yii::t('app','责任人电话')	
        ];
    }
    /**
     * 判断工厂是否真实存在
     */
    public function CheckFactory($id){
    	$factory=Factory::find()->where(['=','id',$id])->exists();
    	if($factory){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    public function CheckFactoryByCode($code){
    	$factory=Factory::find()->where(['=','short_code',$code])->exists();
    	if($factory){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    public function getRandomString($len, $chars=null)
    {
    	if (is_null($chars)){
    		$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    	}
    	mt_srand(10000000*(double)microtime());
    	for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
    		$str .= $chars[mt_rand(0, $lc)];
    	}
    	return $str;
    }
    
    public function getRandomStrNum(){
    	$char1="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	$char2="0123456789";
    	mt_srand(10000000*(double)microtime());
    	for ($i = 0, $str1 = '', $lc = strlen($char2)-1; $i < 1; $i++){
    		$str1 .= $char2[mt_rand(0, $lc)];
    	}
    	
    	for ($i = 0, $str2 = '', $lc = strlen($char1)-1; $i < 1; $i++){
    		$str2 .= $char1[mt_rand(0, $lc)];
    	}
    	return $str1.$str2;
    }
   
}
